var prefix = getProjectName();
function getSupplierType() {
    $('#supplierTypeId').empty();
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/supplier/supplierType/getSupplierList",
        data : {"typeName":$("#checkSupplierName").val()},// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            console.log(data)

            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                htmlText += "<option value='"+item.supplierTypeId+"'> "+item.typeName+" </option>"
            }

            $("#supplierTypeId").append(htmlText);
        }
    });
}

function getLogName() {
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/invocie/logisticsCompany/all",
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            console.log(data)

            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                htmlText += "<option value='"+item.id+"'> "+item.logName+" </option>"
            }

            $("#logisticsId").append(htmlText);
        }
    });
}
function getLogNameByUpdate(logisticId) {
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/invocie/logisticsCompany/all",
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            console.log(data)
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.id == logisticId){
                    htmlText += "<option selected = 'selected' value='"+item.id+"'> "+item.logName+" </option>"
                }else{
                    htmlText += "<option value='"+item.id+"'> "+item.logName+" </option>"
                }

            }

            $("#logisticsId").append(htmlText);
        }
    });
}

function getSupplierTypeByUpdate(typeId) {
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/supplier/supplierType/getSupplierList",
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            console.log(data)
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.supplierTypeId == typeId){
                    htmlText += "<option selected = 'selected' value='"+item.supplierTypeId+"'> "+item.typeName+" </option>"
                }else{
                    htmlText += "<option value='"+item.supplierTypeId+"'> "+item.typeName+" </option>"
                }

            }

            $("#supplierTypeId").append(htmlText);
        }
    });
}

function getDeviceType() {
    $('#deviceTypeId').empty();
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/device/deviceType/getDeviceTypeVOList",
        data : {"typeName":$("#typeName").val()},// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                htmlText += "<option value='"+item.deviceTypeId+"'> "+item.typeName+" </option>"
            }

            $("#deviceTypeId").append(htmlText);
        }
    });
}

function getDeviceTypeByUpdate(typeId) {
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/device/deviceType/getDeviceTypeVOList",
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if(item.deviceTypeId == typeId) {
                    htmlText += "<option selected='selected' value='"+item.deviceTypeId+"'> "+item.typeName+" </option>"
                }else{
                    htmlText += "<option value='"+item.deviceTypeId+"'> "+item.typeName+" </option>"
                }
            }

            $("#deviceTypeId").append(htmlText);
        }
    });
}

function getMaintainType() {
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/device/maintainType/getMaintainTypeList",
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                htmlText += "<option value='"+item.maintainTypeId+"'> "+item.maintainName+" </option>"
            }

            $("#maintainId").append(htmlText);
        }
    });
}

function getMaintainTypeBypdate(typeId) {
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/device/maintainType/getMaintainTypeList",
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.maintainTypeId == typeId){
                    htmlText += "<option selected='selected' value='"+item.maintainTypeId+"'> "+item.maintainName+" </option>"
                }else{
                    htmlText += "<option value='"+item.maintainTypeId+"'> "+item.maintainName+" </option>"
                }

            }

            $("#maintainId").append(htmlText);
        }
    });
}


function getCheckTypeByUpdate(typeId) {
    //console.log("typeId:"+typeId)
    $("#checkTypeId").empty()
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/check/checkType/getCheckTypeList",
        data :{"typeName":$("#typeName").val()},// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.checkTypeId == typeId){
                    htmlText += "<option selected='selected' value='"+item.checkTypeId+"'> "+item.typeName+" </option>"
                }else{
                    htmlText += "<option value='"+item.checkTypeId+"'> "+item.typeName+" </option>"
                }

            }

            $("#checkTypeId").append(htmlText);
        }
    });
}

function getCheckTemplateByUpdate(templateId) {
    $("#checkTemplateId").empty();
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/check/checkTemplate/getCheckTemplateList",
        data : {'templateName':$("#templateName").val()},// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.checkTemplateId == templateId){
                    htmlText += "<option selected='selected' value='"+item.checkTemplateId+"'> "+item.templateName+" </option>"
                }else{
                    htmlText += "<option value='"+item.checkTemplateId+"'> "+item.templateName+" </option>"
                }

            }

            $("#checkTemplateId").append(htmlText);
        }
    });
}

function getCheckTemplateByCheck(templateId) {
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/check/checkTemplate/getCheckTemplateList",
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            htmlText += "<option value='0'> --- 请选择 --- </option>"
            for (var i in itemList){
                var item = itemList[i];
                if (item.checkTemplateId == templateId){
                    htmlText += "<option selected='selected' value='"+item.checkTemplateId+"'> "+item.templateName+" </option>"
                }else{
                    htmlText += "<option value='"+item.checkTemplateId+"'> "+item.templateName+" </option>"
                }

            }

            $("#checkTemplateId").append(htmlText);
        }
    });
}

function getSupplierByUpdate(supplierId) {
    $("#supplierId").empty();
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/supplier/supplier/getSupplierList",
        data : {"supplierName":$("#supplierName").val()},// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.supplierId == supplierId){
                    htmlText += "<option selected='selected' value='"+item.supplierId+"'> "+item.supplierName+" </option>"
                }else{
                    htmlText += "<option value='"+item.supplierId+"'> "+item.supplierName+" </option>"
                }
            }
            $("#supplierId").append(htmlText);
        }
    });
}

function getMaterialByUpdate(materialId) {
    $("#materialId").empty()
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/material/material/getMaterialList",
        data : {'materialName':$("#materialName").val()},// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.materialId == materialId){
                    htmlText += "<option selected='selected' value='"+item.materialId+"'> "+item.materialName+" </option>"
                }else{
                    htmlText += "<option value='"+item.materialId+"'> "+item.materialName+" </option>"
                }
            }
            $("#materialId").append(htmlText);
        }
    });
}

var openDept = function(){
    layer.open({
        type:2,
        title:"选择部门",
        area : [ '300px', '450px' ],
        content:prefix+"/sys/dept/treeView"
    })
}


function getProductByUpdate(productId) {
    $("#productId").empty()
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/product/getProductList",
        data : {"productName":$("#productName").val()},// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.productId == productId){
                    htmlText += "<option selected='selected' value='"+item.productId+"'> "+item.productName+" </option>"
                }else{
                    htmlText += "<option value='"+item.productId+"'> "+item.productName+" </option>"
                }
            }
            $("#productId").append(htmlText);
        }
    });
}
function getProductsByUpdate(productName) {
    $('#productId').empty();
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/product/getProductListByName",
        data : {"productName":$("#checkProductName").val()},
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.productId == productId){
                    htmlText += "<option selected='selected' value='"+item.productId+"'> "+item.productName+" </option>"
                }else{
                    htmlText += "<option value='"+item.productId+"'> "+item.productName+" </option>"
                }
            }
            $("#productId").append(htmlText);
        }
    });
}

function getMarshallingByUpdate(marshallingId) {
    $("#marshalling").empty();
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/marshalling/marshalling/getMarshallingList",
        data :{"marshallingName":$("#marshallingName").val()},// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.marshallingId == marshallingId){
                    htmlText += "<option selected='selected' value='"+item.marshallingId+"'> "+item.marshallingName+" </option>"
                }else{
                    htmlText += "<option value='"+item.marshallingId+"'> "+item.marshallingName+" </option>"
                }
            }
            $("#marshalling").append(htmlText);
        }
    });
}

function getPurchaseByUpdate(purchaseId) {
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/material/purchase/getPurchaseList",
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.purchaseId == purchaseId){
                    htmlText += "<option selected='selected' value='"+item.purchaseId+"'> "+item.purchaseNo+" </option>"
                }else{
                    htmlText += "<option value='"+item.purchaseId+"'> "+item.purchaseNo+" </option>"
                }
            }
            $("#purchaseId").append(htmlText);
        }
    });
}


function getAgent(agentId) {
    $.ajax({
        cache : true,
        type : "GET",
        url : prefix+"/agent/getAgentList",
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            var itemList = data.data;
            var htmlText ="";
            for (var i in itemList){
                var item = itemList[i];
                if (item.agentId == agentId){
                    htmlText += "<option selected='selected' value='"+item.agentId+"'> "+item.agentName+" </option>"
                }else{
                    htmlText += "<option value='"+item.agentId+"'> "+item.agentName+" </option>"
                }
            }
            $("#agentId").append(htmlText);
        }
    });
}